<?LassoScript 

	define_tag(
	'error', -nameSpace='er_', 
	-priority='replace',
	-optional='loc',
	-optional='display');

		local('thisError' = string);
		local('isError' = false);
		local('body' = '');
		local('emailBody' = '');
		local('emailSubject' = server_name+ ' Lasso error');
		local('loc');
		var('sql_error' = false);
		
		// set default display value to true
		!local_defined('display') ? local('display' = true);
		
		//var('return' = false);// use this var so we have a global way to error trap for SQL commands
		
		if(Error_currenterror(-ErrorCode));
			#thisError = Error_currenterror + '- code: ' + Error_currenterror(-ErrorCode);
			#isError = true;
			
		else(File_CurrentError(-ErrorCode));
			#thisError = File_CurrentError + '- code: ' + File_CurrentError(-ErrorCode);
			#isError = true;
		/if;
		
		if(#isError);
			$sql_error = boolean(true);
			#body = '<br>A an error occurred<br>'+ #thisError+'<br>';

			var_defined('sql') ? #body += '<br> SQL:<br>' + $sql + '<br>';
			
			#body += '<br>url: ' + response_filePath;
			#body += '<br>include file: ' + #loc;

			
			#emailBody = 'Errors:\n'+#body;
			if($sendErrorEmail == 'y');
				#emailBody = #emailBody->replace('<br>', '\n');
				
				email_send:
				-to=$errorEmail,
				-from=$siteEmail, 
				-subject=#emailSubject, 
				-html=#body;
				
			/if;
			
			!#display ? #body = string;
			
			return(@#body);
			
		/if;

		
	/define_tag;

?>
